﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DomainModel;
using Utils;
using WebUI.Utils;

namespace WebUI.Models
{
    public class EditJobViewModel : BaseViewModel
    {
        public EditJobViewModel()
            : base()
        { }

        public EditJobViewModel(string jobToken)
            : base(new { JobToken = jobToken })
        { }

        public Job Job { get; set; }

        public IEnumerable<SelectListItem> JobExpList { get; set; }
        public IEnumerable<SelectListItem> JobTypeList { get; set; }

        protected override void SetVarsWhichDependOnDynamicParams(dynamic dynParams)
        {
            string jobToken = dynParams.JobToken;
            string jobGUID = ViewModelUtils.GetJobGUIDFromToken(jobToken);
            int jobID = ViewModelUtils.GetJobIDFromToken(jobToken);
            Job = DataUtils.GetOne<Job>(ConstUtils.SP_GetJobForEdit, new { jobID, CoID = Identity.AccountID });
        }

        public override void SetPublicVarsAfterBindingDynamicParams()
        {
            JobExpList = ViewModelUtils.GetSelectListItems(GlobalUtilities.GetInstance().JobExpList, Job.JobExpID);
            JobTypeList = ViewModelUtils.GetSelectListItems(GlobalUtilities.GetInstance().JobTypeList, Job.JobTypeID);
        }
    }
}